var infectionTemplate = "<tr><td>{{name}}</td>"
    + "<td>{{reason}}</td>"
    + "<td><button type=\"button\" onClick=\"deleteFile('{{name}}')\">Delete</button></td>"
    + "</tr>";

var progressSource;

function startScan()
{
    var scanPath = $("path").value;
    if(!scanPath)
    {
        alert("Error: no path specified!");
        return;
    }
    new Ajax.Request("scan.php", 
    {
        parameters: $H({dir: scanPath}),
        onSuccess: function()
        {
            progressSource = new EventSource("progress.php");
            progressSource.onmessage = getProgress;
        },
        onFailure: function(response)
        {
            alert(response);
        }
    });
}

function getProgress(response)
{
    console.log("Calling getProgress!");
    var newInfections = JSON.parse(response.data);
    newInfections.each(function(infection)
    {
        $("infectionList").insert(Mustache.render(infectionTemplate, infection));
    });
}

function sourceWindow()
{
    window.open("https://github.com/rwhogg/scanMe");
}

function linuxWindow()
{
    window.open("https://www.kernel.org");
}
